#ifndef _CONSOLE_H_
#define _CONSOLE_H_

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

#include <conio.h>

#define CON_KEY_UP          -72
#define CON_KEY_LEFT        -75
#define CON_KEY_RIGHT       -77
#define CON_KEY_DOWN        -80
#define CON_KEY_ESCAPE      27
#define CON_KEY_INSERT      -82
#define CON_KEY_DEL         -83
#define CON_KEY_BACKSPACE   '\b'
#define CON_KEY_ENTER       '\r'
#define CON_KEY_HOME        -71
#define CON_KEY_END         -79
#define CON_KEY_PAGEUP      -73
#define CON_KEY_PAGEDOWN    -81

#define CON_MOUSE_LBTN_DOWN 0x0001
#define CON_MOUSE_LBTN_UP   0x0002
#define CON_MOUSE_RBTN_DOWN 0x0004
#define CON_MOUSE_RBTN_UP   0x0008
#define CON_MOUSE_MBTN_DOWN 0x0010
#define CON_MOUSE_MBTN_UP   0x0020
#define CON_MOUSE_MOVE      0x0100
#define CON_MOUSE_DCLICK    0x0200

typedef
struct
{
	short x;
	short y;
}
point_t;

typedef
struct
{
	short left;
	short top;
	short right;
	short bottom;
}
rect_t;

#define CON_COLOR_BLACK     0x0000
#define CON_COLOR_BLUE      0x0001
#define CON_COLOR_GREEN     0x0002
#define CON_COLOR_RED       0x0004
#define CON_COLOR_YELLOW    CON_COLOR_RED |CON_COLOR_GREEN
#define CON_COLOR_MAGENTA   CON_COLOR_RED | CON_COLOR_BLUE
#define CON_COLOR_CYAN      CON_COLOR_GREEN | CON_COLOR_BLUE
#define CON_COLOR_WHITE     CON_COLOR_GREEN | CON_COLOR_BLUE | CON_COLOR_RED

#define CON_MAX_COLORS      64

extern void     con_init();
extern void     con_deinit();

extern void     con_showCursor();
extern void     con_hideCursor();

extern int      con_gotoXY(int x, int y);
extern int      con_getXY(int *px, int *py);
extern int      con_getMaxXY(int *px, int *py);

extern int      con_gotoPoint(point_t cursor);
extern int      con_getPoint(point_t * pcursor);
extern int      con_getMaxPoint(point_t * pmaxpos);

extern int      con_clearScr();

extern int      con_outTxt(const char *format, ...);

extern int      con_keyPressed();
extern int      con_getKey(point_t * pmouse);
extern int      con_isMouse(int key);

/*
 * You can init "color pairs": tuple of foreground color and
 * background color. This pairs can be set before any drawing
 * which use corresponding colors.
 */

extern int      con_initPair(short n, short fg, short bg);
extern int      con_setColor(short n);

#ifdef __cplusplus
}
#endif // __cplusplus
#endif // _CONSOLE_H_
